-
Notifications
You must be signed in to change notification settings - Fork 0
일과화면 리팩토링 #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
일과화면 리팩토링 #183
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
확신은 없다..
현재 흐름은 그러하게 화면 이동이 가능한데.. 제대로 동작은 안함
현재 흐름은 그러하게 화면 이동이 가능한데.. 제대로 동작은 안함
…이 되는 문제 #182 # 1. 상태가 확정된 다음 navigation을 하자. ❗ 문제 설명 DailyCertifyRoute에서 CertifyStatus.CONFIRMED가 되면 → onNavigateToDetailRequest() 호출 navController.navigate(...)로 DailyCertifyDetailRoute로 이동 그런데 DailyCertifyViewModel은 여전히 같은 인스턴스를 공유 중 그런데 Compose는 LaunchedEffect(uiState.certifyStatus)를 재실행하면서 또 navigate 호출하지 않도록 조건을 신중히 처리해야 함 ✅ 왜 CertifyStatus.PENDING으로 보이는가? 가능성: ① completeCertify()가 아직 완료되기 전에 navigation이 먼저 호출됨 → LaunchedEffect가 CONFIRMED를 감지하긴 하지만 UI 상태 업데이트보다 빠르게 navigate() 호출 ② DailyCertifyDetailRoute에서 ViewModel은 공유되지만 → 화면에 재조합되는 시점에서 여전히 이전 상태 (PENDING)이 반영되어 보임 → 특히 DailyCertifyScreen 내부가 LaunchedEffect나 remember로 캐싱된 UI 상태를 보고 있을 가능성 ----해결------ ```kotlin onCertifyCompleteRequest = { viewModel.completeCertify() // ← 상태가 바로 반영되도록 되자마자 UI recomposition 유도 // 그리고 이후에 navigate 트리거 } val hasNavigated = remember { mutableStateOf(false) } LaunchedEffect(uiState.certifyStatus) { if (uiState.certifyStatus == CertifyStatus.CONFIRMED && !hasNavigated.value) { hasNavigated.value = true onNavigateToDetailRequest() } } ``` LaunchedEffect(certifyStatus)에서 navigation 트리거는 유지하되, LaunchedEffect는 다음처럼 한 번만 실행되도록 기억시키는 것도 중요 # 2. 하나의 ViewModel 인스턴스를 공유해야 함 이전 코드 구조에선 DailyCertifyRoute와 DailyCertifyDetailRoute에서 viewModel: DailyCertifyViewModel = hiltViewModel() 를 각자 선언하고 있었기 때문에, 각 Route 진입 시 마다 다른 ViewModel 인스턴스가 생성되어 상태 초기화가 발생하는 겁니다. DailyCertifyRoute 와 DailyCertifyDetailRoute 모두 EditCertifyActivity에서 선언한 ViewModel을 prop으로 받아야 합니다. 📌 Point: hiltViewModel() 을 Route 내부에서 여러 번 호출하면, Navigation Graph Scope로 인해 서로 다른 인스턴스가 됩니다. 반드시 Activity 단에서 viewModel() 호출해서 전달하는 방식이 중요합니다. 현재 문제는 ViewModel 범위가 Route마다 달라서 상태가 공유되지 않는 것입니다. viewModel = viewModel()을 Activity에서 한 번만 호출하고, 모든 Composable에 명시적으로 넘겨주세요.
1. 댓글 작성·수정·닫기 핸들러 파라미터 추가로 ViewModel 로직 분리 - onCommentWrite, onCommentEditSubmit, onBottomSheetDismiss 파라미터 추가 - Route에서 ViewModel 로직 처리, Screen은 UI 렌더링에 집중하도록 분리 2. BottomSheet dismiss 후 상태 재호출이 불가능한 문제 수정 - sheetState.isVisible과 ViewModel 상태 간 불일치 감지해 dismiss 처리 - dismiss 이후에도 다시 ViewModel 호출로 BottomSheet를 재진입 가능하게 개선
Screen에 파라미터 만들고, remember 변수도 만들고
Member
|
혹시 GPT 쓰셨아요...? |
Collaborator
Author
|
쓰긴 쓰죠?? |
agvber
approved these changes
Jun 2, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🤷♂️ PR 내용(Issue 꼭 달기!)
resolved: #113
감사합니다!! 일단 이슈대로 해봤는데 빠진건 차차 수정하겠습니다!